<?php
header('Content-Type:text/html;charset=utf-8');
error_reporting(E_ALL^E_NOTICE);
$word = !empty($_GET['word']) ? trim($_GET['word']) : '';
$page = !empty($_GET['page']) ? $_GET['page'] : 1;
if(!empty($word) && !empty($page)){
$url = 'http://m.weibo.cn/page/pageJson?containerid=100103type%3D1%26q%3D%'.$word.'&page='.$page.'&uicode=10000011&fid=100103type%3D1%26q%3D%E9%99%88%E4%B9%94%E6%81%A9&ext=sourceType%3A&rl=1';
//http://m.weibo.cn/main/pages/index?containerid=100103type%3D1%26q%3D%E9%99%88%E4%B9%94%E6%81%A9&type=all&queryVal=%E9%99%88%E4%B9%94%E6%81%A9&title=%E9%99%88%E4%B9%94%E6%81%A9

echo '<p><a href="javascript:history.go(-1)">return </a></p>';
$content = file_get_contents($url);
$contents =  json_decode($content);
echo '<style>
    table{border:1px solid grey; border-collapse:collapse}
    td{border:1px solid grey}
    </style>';
echo "<table><tr>";
echo "<td>微博ID</td>";
echo "<td>详细内容</td>";
echo "<td>创建时间</td>";
echo "<td>微博来源</td>";
echo "<td>转</td>";
echo "<td>评</td>";
echo "<td>好</td>";
echo "<td>转载ID</td>";
echo "<td>转载用户ID</td>";
echo "<td>转载用户名</td>";
echo "<td>详情URL</td>";
//echo "<td>缩略图地址</td>";
//echo "<td>中等图地址</td>";
//echo "<td>原始图地址</td>";
echo "<td>博主ID</td>";
echo "<td>博主微博地址</td>";
echo "<td>呢称</td>";
echo "<td>描述</td>";
echo "<td>头像</td>";
echo "<td>粉丝</td>";
echo "<td>关注</td>";
echo "<td>是否加V</td>";
echo "</tr>";
foreach($contents->cards as $card){
    $cc = $card;
}
foreach($cc->card_group as $group){
echo "<tr>";
    echo '<td>'.$group->mblog->mid.'</td>';
    echo '<td>'.$group->mblog->text.'</td>';
    echo '<td>'.$group->mblog->created_timestamp.'</td>';
    echo '<td>'.$group->mblog->source.'</td>';
    echo '<td>'.$group->mblog->reposts_count.'</td>';
    echo '<td>'.$group->mblog->comments_count.'</td>';
    echo '<td>'.$group->mblog->attitudes_count.'</td>';
    echo '<td>'.$group->mblog->retweeted_status->id.'</td>';
    echo '<td>'.$group->mblog->retweeted_status->user->id.'</td>';
    echo '<td>'.$group->mblog->retweeted_status->user->screen_name.'</td>';
    echo '<td>'.$group->scheme.'</td>';
    //echo '<td>'.$group->mblog->mid.'</td>';
    //echo '<td>'.$group->mblog->mid.'</td>';
    //echo '<td>'.$group->mblog->mid.'</td>';
    echo '<td>'.$group->mblog->user->id.'</td>';
    echo '<td>'.$group->mblog->user->profile_url.'</td>';
    echo '<td>'.$group->mblog->user->screen_name.'</td>';
    echo '<td></td>';
    echo '<td>'.$group->mblog->user->profile_image_url.'</td>';
    echo '<td>'.$group->mblog->user->fansNum.'</td>';
    echo '<td></td>';
    echo '<td>'.$group->mblog->user->verified.'</td>';
echo "</tr>";
}
echo '</table>';

echo '<pre>';
print_r( json_decode($content));
}else{
?>
<p>
    wap方式直接获取微博信息
</p>
<form  method='get'>
<p>
    <label for="keyword">关键词</label>
    <input type="text" name="word" value="">
</p>
<p>
    <label for="page">页码</label>
    <input type="text" name="page" value="">
</p>
<p>
    <input type="submit" name="" value="查询">
</p>

</form>
<?php
}
?>
